import { store } from "@/store"
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { showError } from '@/utils/msg-show'
import { getAllApi } from '@/api/sys/defConfig'

export const useDefaultConfigStore = defineStore("DefaultConfig", () => {

	const isZero = ref(true)
    const dataList = ref()

	/** 获取默认费率 */
	async function getAll(){
		await getAllApi().then((res: any) => {
			dataList.value = res.data
		}).catch(err => {
			showError(err.msg || err.errMsg || err)
		})
	}

	/** 初始化 */
	async function init() {
		if (isZero.value) {
            await getAll()
			isZero.value = false
		}
	}
   
	return {
		init, 
        dataList,
	}

})

export function useDefaultConfigStoreHook() {
	return useDefaultConfigStore(store);
}